﻿package Cain.bulanMove
{
	import flash.geom.Point;
	
	/**
	 * 布朗隨機運動  v1.1 2010.10.05
	 * @author Cain@2009 in ADCAST
	 */
	public class BulanMovePoint extends Point 
	{
		private var x0:Number;
		private var y0:Number;
		private var vv:Number;
		private var ax:Number=0;
		private var ay:Number=0;
		private var vx:Number = 0;
		private var vy:Number = 0;
		private var _live:int = 0;
		/**
		 * 初始化設定
		 * @param	_x 初始x
		 * @param	_y 初始y
		 * @param	_v 最高速度動量
		 */
		public function BulanMovePoint(_x:Number=0,_y:Number=0,_v:Number=.5)
		{
			x0 = _x;
			y0 = _y;
			vv = _v;
			init();
		}
		
		private function init():void
		{
			x = x0;
			y = y0;
		}
		/**
		 * 移動一次
		 * @param	_add_x 增加 x
		 * @param	_add_y 增加 y
		 */
		public function move(_add_x:Number = 0,_add_y:Number=0):void 
		{
			ax = Math.random() * vv - vv / 2;
			ay = Math.random() * vv - vv / 2;
			vx += ax;
			vy += ay;
			x += (vx+_add_x);
			y += (vy+_add_y);
			_live++;
		}
		/**
		 * 設定動量
		 */
		public function set v(_v:Number):void 
		{
			vv = _v;
		}
		/**
		 * 經過壽命 (移動次數)
		 */
		public function get live():int 
		{
			return _live;
		}
	}
	
}